package com.sport.common.utils;


import cn.hutool.core.util.RandomUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.AES;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;

import javax.crypto.SecretKey;

public class PasswordUtils {

    /**
     *  加密
     * @param slat 盐
     * @param password 密码
     * @return 生成加密后的密码
     */
    public static String encrypt(String slat,String password){
        //生成秘钥
        byte[] encoded = SecureUtil.generateKey(SymmetricAlgorithm.AES.getValue(), slat.getBytes()).getEncoded();
        //返回加密
        AES aes = SecureUtil.aes(encoded);
        return aes.encryptBase64(password);
    }

    public static String decrypt(String slat,String password){
        //生成秘钥
        byte[] encoded = SecureUtil.generateKey(SymmetricAlgorithm.AES.getValue(), slat.getBytes()).getEncoded();
        //返回解密
        AES aes = SecureUtil.aes(encoded);
        return aes.decryptStr(password);
    }

}
